package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.request.DicRequest;
import com.bodu.system.entity.vo.DicVo;
import com.bodu.system.service.DicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 字典表 API
* @author Administrator
*/
@Api(tags = "字典表 API")
@RestController
@RequestMapping("/dic")
public class DicController extends AbstractCommonController<DicService, DicRequest, DicVo>{

    private final DicService dicService;

    public DicController(DicService dicService) {
        this.dicService = dicService;
    }

    @TraceLog()
    @ApiOperation("详情")
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(dicService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存字典表")
    public Result<Integer> save(@RequestBody DicRequest dicRequest) {
        return super.save(dicService, dicRequest);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新字典表")
    public Result<Integer> update(@RequestBody DicRequest dicRequest) {
        return super.update(dicService, dicRequest);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("字典表-查询")
    public Result<List<DicVo>> listPage(@RequestBody ParamReq<DicRequest> req)  {
        return super.listPage(dicService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("字典表-统计")
    public Result<Integer> countPage(@RequestBody ParamReq<DicRequest> req)  {
        return super.countPage(dicService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("字典表-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<DicRequest> req)  {
        return super.page(dicService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除字典表")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(dicService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除字典表")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(@PathVariable("ids") List<Long> ids) {
        return super.batchDelete(dicService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
